﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GameCore
{
    public abstract  class Singleton<T> where T:class,new()
    {
        private static T m_instance;
        private static readonly object obj = new object();

        public static T Instance
        {
            get
            {


                if (m_instance==null)
                {
                    lock (obj)
                    {
                        if (m_instance == null)
                        {
                            m_instance = new T();
                        }
                    }
              
                }
                return m_instance;
            }
        }


        /// <summary>
        ///  创建单例实例
        /// </summary>
        public static T CreateSingleton()
        {
            return Instance;
        }
        protected Singleton()
        {
            Init();
        }
        /// <summary>
        /// 初始化
        /// </summary>
        protected virtual void Init()
        {
            
        }
    }
}
